//
//  BJCitizenCard.m
//  SZBank
//
//  Created by rimi on 16/7/19.
//  Copyright © 2016年 LuoYao. All rights reserved.
//

#import "BJCitizenCard.h"
#import "BJWebView.h"
@interface BJCitizenCard ()<CustomerNavigationBarsDelegate,UIWebViewDelegate>
{
   CGFloat frameWidth;/**< 自身宽度 */
    CGFloat frameHeight;/**< 自身高度 */
    NSDictionary *dataDictionary;/**< 数据源数组 */
    
    CGRect backGrounViewBounds; /**< 背景视图尺寸 */
}
@property (nonatomic)CustomerNavigationBars *customNavigation;/**< 导航条 */
@property (nonatomic)UIView *backGroundView;/**< 背景视图 */
@end
@implementation BJCitizenCard

/**
 *  初始化方法
 */
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //添加背景
        self.userInteractionEnabled = YES;
        self.image = [LocalDataManager getImageWithSourceOfPath:@"背景"];
        //赋值高度宽度
        frameWidth = self.frame.size.width;
        frameHeight = self.frame.size.height;
        backGrounViewBounds = self.backGroundView.bounds;
   //初始化数据源字典
        dataDictionary = [NSDictionary dictionary];
        //添加背景视图
    
        
        UIImageView *shadowView= [[UIImageView alloc]initWithFrame:CGRectMake(0,backGrounViewBounds.size.height * 0.97  , backGrounViewBounds.size.width, backGrounViewBounds.size.height * 0.06)];
        shadowView.image = [LocalDataManager getImageWithSourceOfPath:@"金融资讯_底边"];
        [self.backGroundView addSubview:shadowView];
        [self addSubview:self.backGroundView];
        //网络访问
    [NetWorkingDataManager getProtocolTemplateUpdateWithProtocolid:@"402880c43fe15a11013fe15e2e0f0001" success:^(id sender) {
        dataDictionary = sender[5][@"protocolData"];
        
        //添加导航条
         self.customNavigation = [[CustomerNavigationBars alloc]initWithFrame:CGRectMake(0, 10, frameWidth, frameHeight * 0.06) btnTitleArray:sender[0][@"attributeOrder"]];
        //设置导航条代理
        self.customNavigation.delegate = self;
        [self addSubview:_customNavigation];
        
        //添加默认视图
        BJWebView *functionView = [[BJWebView alloc]initWithFrame:CGRectMake(backGrounViewBounds.size.width * 0.06, 0, backGrounViewBounds.size.width * 0.9, backGrounViewBounds.size.height * 0.93) withHTMLString:dataDictionary[@"功能介绍"][0]];
        [self.backGroundView addSubview:functionView];

        

    } failure:^(id sender) {
        NSLog(@"失败%@",sender);
    }];
    }
    return self;
}

#pragma mark -- CustomerNavigationBarsDelegate

- (void)customeNavigationBarView:(CustomerNavigationBars *)customeNavigationBarView didSelectButton:(UIButton *)didSelectButton{
    //先移除所有视图
    [self.backGroundView.subviews  makeObjectsPerformSelector:@selector(removeFromSuperview)];
    UIImageView *shadowView= [[UIImageView alloc]initWithFrame:CGRectMake(0,backGrounViewBounds.size.height * 0.97  , backGrounViewBounds.size.width, backGrounViewBounds.size.height * 0.06)];
    shadowView.image = [LocalDataManager getImageWithSourceOfPath:@"金融资讯_底边"];
    [self.backGroundView addSubview:shadowView];
//添加视图
    switch (didSelectButton.tag - 1000) {
        case 0:
        {
            BJWebView *functionView = [[BJWebView alloc]initWithFrame:CGRectMake(backGrounViewBounds.size.width * 0.06, 0, backGrounViewBounds.size.width * 0.9, backGrounViewBounds.size.height) withHTMLString:dataDictionary[@"功能介绍"][0]];
            [self.backGroundView addSubview:functionView];
        }
            break;
        case 1:
        {
            BJWebView *functionView = [[BJWebView alloc]initWithFrame:CGRectMake(backGrounViewBounds.size.width * 0.06, 0, backGrounViewBounds.size.width * 0.9, backGrounViewBounds.size.height) withHTMLString:dataDictionary[@"激活情况"][0]];
            [self.backGroundView addSubview:functionView];
        }
            break;
        case 2:
        {
            BJWebView *functionView = [[BJWebView alloc]initWithFrame:CGRectMake(backGrounViewBounds.size.width * 0.06, 0, backGrounViewBounds.size.width * 0.9, backGrounViewBounds.size.height) withHTMLString:dataDictionary[@"金融使用指南"][0]];
            [self.backGroundView addSubview:functionView];
        }
            break;
        case 3:
        {
            BJWebView *functionView = [[BJWebView alloc]initWithFrame:CGRectMake(backGrounViewBounds.size.width * 0.06, 0, backGrounViewBounds.size.width * 0.9, backGrounViewBounds.size.height) withHTMLString:dataDictionary[@"挂失"][0]];
            [self.backGroundView addSubview:functionView];
        }
            break;
        case 4:
        {
            BJWebView *functionView = [[BJWebView alloc]initWithFrame:CGRectMake(backGrounViewBounds.size.width * 0.06, 0, backGrounViewBounds.size.width * 0.9, backGrounViewBounds.size.height) withHTMLString:dataDictionary[@"申办流程"][0]];
            [self.backGroundView addSubview:functionView];
        }
            break;
        case 5:
        {
            BJWebView *functionView = [[BJWebView alloc]initWithFrame:CGRectMake(backGrounViewBounds.size.width * 0.06, 0, backGrounViewBounds.size.width * 0.9, backGrounViewBounds.size.height) withHTMLString:dataDictionary[@"补卡"][0]];
            [self.backGroundView addSubview:functionView];
        }
            break;
        case 6:
        {
            BJWebView *functionView = [[BJWebView alloc]initWithFrame:CGRectMake(backGrounViewBounds.size.width * 0.06, 0, backGrounViewBounds.size.width * 0.9, backGrounViewBounds.size.height) withHTMLString:dataDictionary[@"密码管理"][0]];
            [self.backGroundView addSubview:functionView];
        }
            break;
            
        case 7:
        {
            BJWebView *functionView = [[BJWebView alloc]initWithFrame:CGRectMake(backGrounViewBounds.size.width * 0.06, 0, backGrounViewBounds.size.width * 0.9, backGrounViewBounds.size.height) withHTMLString:dataDictionary[@"8大免费"][0]];
            [self.backGroundView addSubview:functionView];
        }
            break;
        case 8:
        {
            BJWebView *functionView = [[BJWebView alloc]initWithFrame:CGRectMake(backGrounViewBounds.size.width * 0.06, 0, backGrounViewBounds.size.width * 0.9, backGrounViewBounds.size.height) withHTMLString:dataDictionary[@"常见问题"][0]];
            [self.backGroundView addSubview:functionView];
        }
            break;
        case 9:
        {
            BJWebView *functionView = [[BJWebView alloc]initWithFrame:CGRectMake(backGrounViewBounds.size.width * 0.06, 0, backGrounViewBounds.size.width * 0.9, backGrounViewBounds.size.height) withHTMLString:dataDictionary[@"银医一卡通"][0]];
            [self.backGroundView addSubview:functionView];
        }
            break;
        case 10:
        {
            BJWebView *functionView = [[BJWebView alloc]initWithFrame:CGRectMake(backGrounViewBounds.size.width * 0.06, 0, backGrounViewBounds.size.width * 0.9, backGrounViewBounds.size.height) withHTMLString:dataDictionary[@"服务中心"][0]];
            [self.backGroundView addSubview:functionView];
        }
            break;
            
            
            
        default:
            break;
    }
  
    
   
}

#pragma mark -- getters
- (UIView *)backGroundView{
    if (!_backGroundView) {
        _backGroundView = [[UIView alloc]initWithFrame:CGRectMake(frameWidth * 0.03, frameHeight * 0.1, frameWidth * 0.95, frameHeight * 0.8)];
        _backGroundView.layer.cornerRadius = frameWidth * 0.01;
        _backGroundView.backgroundColor = [UIColor whiteColor];
        _backGroundView.userInteractionEnabled = YES;
        
    }
    return _backGroundView;
}
@end
